﻿using System;
using System.Collections.Generic;
using RentalSystem.Data.EF.Core;

namespace RentalSystem.Data.EF.Dao
{
    public class EFUserLogsDao : IUserLogsDao
    {
        #region Queries

        private static string ListByGuidQuery;

        #endregion

        private EFManager<UserLogs> manager;

        public EFUserLogsDao(RentalDatabaseEntities repository)
        {
            ListByGuidQuery = "SELECT VALUE ul FROM UserLogs AS ul WHERE ul.UserGuid = @Guid;";

            this.manager = new EFManager<UserLogs>(repository);
        }

        #region IDao2Keys

        public UserLogs Add(UserLogs entity)
        {
            manager.Database.AddToUserLogs(entity);
            manager.Save();
            return entity;
        }

        public UserLogs Get(string id1, DateTime id2)
        {
            throw new NotImplementedException();
        }

        public void Delete(string id1, DateTime id2)
        {
            throw new NotImplementedException();
        }

        public void DeleteBy1Key(string id1)
        {
            throw new NotImplementedException();
        }

        public void DeleteBy2Key(string id2)
        {
            throw new NotImplementedException();
        }

        public void Delete(UserLogs entity)
        {
            throw new NotImplementedException();
        }

        public void Update(UserLogs entity, uint fields)
        {
            throw new NotImplementedException();
        }

        public List<UserLogs> List()
        {
            throw new NotImplementedException();
        }

        #endregion

        public List<UserLogs> ListByUser(string userGuid)
        {
            QueryParam[] parameters = new QueryParam[]
                {
                    new QueryParam("@Guid", userGuid)
                };

            var logs = manager.SQLQueryToEntity(ListByGuidQuery, parameters);

            List<UserLogs> result = new List<UserLogs>();

            foreach (UserLogs log in logs)
            {
                result.Add(log);
            }

            return result;
        }
    }
}
